package com.sbl.bajw.pc.action;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.sbl.bajw.common.web.JsonResultUtil;
import com.sbl.bajw.common.web.RequestUnit;
import com.sbl.bajw.pc.model.FeedBackModel;
import com.sbl.bajw.pc.service.FeedBackService;
import com.sbl.bajw.util.JsonUtil;

/**
 * @作者：罗琦
 * @类名： FeedBackAction
 * @类作用：意见反馈增删改查
 * @时间：2015年5月5日
 */
@Controller
@RequestMapping("/FeedBack")
public class FeedBackAction {

	@Resource
	private FeedBackService service;
	
	/**
	 * @标题：createApp
	 * @作者：Administrator
	 * @时间：2015年5月5日
	 * @作用：用户意见反馈插入
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/createApp")
	public @ResponseBody String createApp(HttpServletRequest request, HttpServletResponse response) throws Exception{
		FeedBackModel model = RequestUnit.getModel(FeedBackModel.class);
		service.insert(model);
		return JsonResultUtil.Success();
	}
	
	/**
	 * @标题：getListApp
	 * @作者：罗琦
	 * @时间：2015年5月15日
	 * @作用：用户反馈列表APP展示
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/getListApp")
	public @ResponseBody String getListApp(HttpServletRequest request, HttpServletResponse response){
		String id = RequestUnit.getString("user_id");
		List<FeedBackModel> list = service.getListApp(id);
		String json = JsonResultUtil.Success(JsonUtil.ConvertArrayToJson(list));
		return json;
	}
	
	/**
	 * @标题：detailApp
	 * @作者：罗琦
	 * @时间：2015年5月15日
	 * @作用：APP用户反馈详情展示
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/detailApp")
	public @ResponseBody String detailApp(HttpServletRequest request, HttpServletResponse response){
		String id = RequestUnit.getString("feedbackId");
		HashMap<String, Object> model = service.getModelApp(id);
		List<HashMap<String, String>> pics = service.getPics(id);
		
		String result = "{\"image\":" + JsonUtil.ConvertArrayToJson(pics) + ",\"data\":" + JsonUtil.ConvertObjectToJson(model) + "}";
		return JsonResultUtil.Success(result);
	}
	
	/**
	 * @标题：getList
	 * @作者：罗琦
	 * @时间：2015年6月8日
	 * @作用：用户反馈列表后台展示
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/getList")
	public @ResponseBody String getList(HttpServletRequest request, HttpServletResponse response){
		HashMap<String, Object> parm = RequestUnit.getHashMapParmO();
		String json = service.getList(parm);
		return json;
	}
	
	@RequestMapping(value = "/List")
	public ModelAndView List(HttpServletRequest request, HttpServletResponse response){
		ModelAndView mav = new ModelAndView("/view/manager/FeedBack/List");
		return mav;
	}

	@RequestMapping(value = "/detail")
	public ModelAndView detail(HttpServletRequest request, HttpServletResponse response){
		String id = RequestUnit.getString("id");
		HashMap<String, Object> result = service.getModel(id);
		List<HashMap<String, String>> pics = service.getPics(id);
		request.setAttribute("model", result);
		request.setAttribute("pics", pics);
		ModelAndView mav = new ModelAndView("/view/manager/FeedBack/Detail");
		return mav;
	}
}
